﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AgriMarketWebProj.Controllers
{
    public class UserAccountController : Controller
    {
        //
        // GET: /UserAccount/

        public ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        public ActionResult LogIn()
        {

            if (Session["CurrentUserAccount"] == null)
            {
                string returnUrl = (string)TempData["ReturnUrl"];
                ViewBag.ReturnUrl = returnUrl;
                return View();
            }
            else
            {
                return RedirectToAction("Index", "Auction");
            }
        }
        [HttpPost]
        public ActionResult LogIn(string userAccountInput, string userPasswordInput,string returnUrl)
        {
            AgriMarketService.AgriMarketWebService service = new AgriMarketService.AgriMarketWebService();
            if (service.CheckLogIn(userAccountInput, userPasswordInput))
            {
                Session["CurrentUserAccount"] = userAccountInput;
                if(returnUrl.Trim()!="")
                    return Redirect(returnUrl);
                return RedirectToAction("Index", "Auction");
            }
            else
            {
                return Content("sai");
            }
        }
        public ActionResult LogOut()
        {
            Session.Remove("CurrentUserAccount");
            return View("LogIn");
        }
    }
}
